ENT.Type = "anim"
ENT.Base = "base_gmodentity"
 
ENT.PrintName		= "Accessory"
ENT.Author			= "x-quake"
ENT.Contact			= "NA"
ENT.Purpose			= "Server-use"
ENT.Instructions	= "Spawn it."


//HatModel = "models/props_junk/TrafficCone001a.mdl"

//Edit this file to accord for Item TYPES and change the bones accordingly. For the BODY types (Wings) add the animation code. Make sure Shoes, Arms, and Hands are on both sides of the player.

if SERVER then

function ENT:Initialize()
	
	self.Entity:SetParent( self.Entity:GetOwner() )
	//self.Entity:SetModel( HatModel )
	self.Entity:SetMoveType( MOVETYPE_NONE )
	self.Entity:SetSolid( SOLID_NONE )
	self.Entity:SetCollisionGroup( COLLISION_GROUP_NONE )
	self.Entity:DrawShadow( false )
	
end

function ENT:Think()

	if self.Entity:GetOwner():GetViewEntity():GetClass() == "gmod_cameraprop" and self:GetNetworkedString( "ViewEnt" ) != "camera" then
		self:SetNetworkedString( "ViewEnt", "camera" )
	elseif self.Entity:GetOwner():GetViewEntity():GetClass() != "gmod_cameraprop" and self:GetNetworkedString( "ViewEnt" ) != "player" then
		self:SetNetworkedString( "ViewEnt", "player" )
	end

end

end



if CLIENT then

function ENT:Draw()
	local Own = nil
		if self.Entity:GetOwner() then Own = self.Entity:GetOwner() end
	local Offset = self.Entity:GetNetworkedVector( "offset" )
	local Scale = self.Entity:GetNetworkedVector( "scale" )
	local rotation = self.Entity:GetNetworkedAngle( "rotation" )
	local itype = self.Entity:GetNetworkedString( "type" )
	
	if not Own:Alive() then
		Own = self:GetOwner():GetRagdollEntity()
	end
	
	if Own then
	local BONE = nil
	local BONE2 = nil
	local Bone3 = nil
	local Bone4 = nil
		
		if itype == "HAT" or itype == "HEAD" or itype == "FACE" then
			BONE = Own:LookupBone("ValveBiped.Bip01_Head1")
		elseif itype == "SHOES" then
			BONE = Own:LookupBone("ValveBiped.Bip01_R_Foot")
			BONE2 = Own:LookupBone("ValveBiped.Bip01_L_Foot")
		elseif itype == "ARMS" then
			BONE = Own:LookupBone("ValveBiped.Bip01_R_UpperArm")
			BONE2 = Own:LookupBone("ValveBiped.Bip01_R_Forearm")
			BONE3 = Own:LookupBone("ValveBiped.Bip01_L_UpperArm")
			BONE4 = Own:LookupBone("ValveBiped.Bip01_L_Forearm")
		elseif itype == "HANDS" then
			BONE = Own:LookupBone("ValveBiped.Bip01_R_Hand")
			BONE2 = Own:LookupBone("ValveBiped.Bip01_L_Hand")
		end
		local BP, BA = Own:GetBonePosition( BONE )
		
			self.Entity:SetPos( BP + (BA:Right() * Offset.z) + (BA:Forward() * Offset.x) + (BA:Up() * Offset.y) )
			BA:RotateAroundAxis( BA:Forward(), rotation.p )
			BA:RotateAroundAxis( BA:Up(), rotation.r )
			BA:RotateAroundAxis( BA:Right(), rotation.y )
			self.Entity:SetAngles( BA )
			self.Entity:SetModelScale( Scale )
			if LocalPlayer() != self.Entity:GetOwner() or self:GetNetworkedString( "ViewEnt" ) == "camera" or Own == self:GetOwner():GetRagdollEntity() then
				self.Entity:DrawModel()
			end
			
	end

end

end